-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove 0-size and variable size array members #13945
Conversation
built fine on msvc straight away, nicely done. |
struct { | ||
int64_t isref; | ||
Function *f; | ||
} data[]; | ||
} data[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure this change isn't ISO-conforming C. The old version should have been more correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is not ISO-conforming about this?
The warning I get is
yuyichao% LANG=C g++ -pedantic -x c++ -Wall -Wextra - -c -o /dev/null <<EOF
typedef struct {
int a;
int b[];
} A;
EOF
<stdin>:3:8: warning: ISO C++ forbids zero-size array 'b' [-Wpedantic]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK so I find this stackoverflow thread. And it seems that there basically isn't a ISO C++ conforming way to do this.
- The flexible member is invalid C++ syntax and causes warning under
-pedantic
. - The single element array could technically be UB but
It's not clear if it's legal or portable, but it is rather popular.
anddoes seem to work under all known implementations
.... (and also issue no warnings.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does seem to work under all known implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we should just switch this struct to a std::unordered_map< uint64_t, Function* >
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing the [1] thing can now give you runtime errors on OS X, cf #13845
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we should just switch this struct to a
std::unordered_map< uint64_t, Function* >
We don't require c++11
in general yet but it could be std::map
? Looks like it currently is simply a std::vector
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::vector< std::pair< int64_t, Function* > >
would also work. it's expected to be a very small set, so actually it's best not to use unordered_map
, which may significantly over-allocate.
f8431c0
to
6db03d0
Compare
I updated the PR to not use
The |
lgtm |
6db03d0 looks like it also works on msvc. Do any of the embedding docs or examples need updating for this? |
Good question. All the changes are API level details (i.e. shouldn't break ABI) and it seems that none of these are covered by the embedding doc. (We don't have doc for the various |
6db03d0
to
df7febe
Compare
Rebased to resolve conflict with #13787 .... I guess I shouldn't have silently included the fix for the variable not used warning when assert is off.... |
Oops, i guess at least one of us shouldn't have silently added that fix. We very nearly came up with the same patch too :/ |
df7febe
to
63f3edf
Compare
Rebased and add a short comment about |
Remove 0-size and variable size array members
This flag is added by llvm-config 3.7 on ArchLinux. Ref #13945
This flag is added by llvm-config 3.7 on ArchLinux. Ref #13945
This flag is added by llvm-config 3.7 on ArchLinux. Ref #13945
This flag is added by llvm-config 3.7 on ArchLinux. Ref #13945
This flag is added by llvm-config 3.7 on ArchLinux. Ref #13945
This flag is added by llvm-config 3.7 on ArchLinux. Ref #13945
This flag is added by llvm-config 3.7 on ArchLinux. Ref #13945
For some reason, the
llvm-config
from LLVM 3.7 adds-pedantic
to cflags and cxxflags. This causes a huge amount of compiler warnings (mainly because ofJL_DATA_TYPE
). I couldn't find out why did LLVM starts doing this or how to workaround it in general so I decided to fix most of the warnings....This PR doesn't completely fix all the
-Wpedantic
warnings (the ones that are not fixed is anonymous structs which we use for bitsfields in a union. This turns out to be valid C11 but not valid C++ yet...).This could break embedding. In particular,
jl_value_t
is only a declaration now. Direct use ofjl_value_t
instead ofjl_value_t*
shouldn't be necessary.jl_value_t::fieldptr
We already have
jl_data_ptr
and this macro should be used instead.jl_sym_t::data
Use
jl_symbol_name
, which is also the name of the exported function.jl_taggedvalue_t::value
(not actually a flexible array member but was serving a similar purpose). I doubt any embedding code manipulate
jl_taggedvalue_t
directly butjl_valueof
is provided as a convenient way to access the value pointer.jl_svec_t::data
We already have
jl_svec_data
and this macro should be used instead.jl_datatype_t::fields
This shouldn't be accessed directly since Variable size field descriptors #13147.
jl_datatype_fields
macro is also added to get the address of the fields in the rare case it is needed.JL_DATA_TYPE
in a non-gc allocatedstruct
to provide necessary alignment, it needs to find another way to do it. (define its own zero length array member, use the alignment attributes etc.)jl_valueof
macro and function could be used as a compile time and runtime check to detect this change.@vtjnash Ref #13787
@tkelman This should make the code more MSVC compatible but it's also possible that I break something without realizing it....